package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDto;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    //条件查询文章内容列表
    @PostMapping("/list")
    public ResponseResult getNewsList(@RequestBody WmNewsPageReqDto dto) {
        //调用servcie
        return wmNewsService.getNewsList(dto);
    }

    /**
     * 发布文章
     *
     * @param dto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto dto) {
        return wmNewsService.submit(dto);
    }

    /**
     * 自媒体文章上下架
     *
     * @param dto
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUpNews(@RequestBody WmNewsDto dto) {
        //调用service
        return wmNewsService.downOrUpNews(dto);
    }


    /**
     * 平台管理,分页条件查询自媒体文章列表
     *
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult getNewsListVo(@RequestBody NewsAuthDto dto) {
        log.info("平台管理端:分页条件查询自媒体文章:{}", dto);
        //调用service
        return wmNewsService.getNewsWithAuthorName(dto);
    }

    /**
     * 查询文章详情
     *
     * @param id
     * @return
     */
    @GetMapping("/one_vo/{id}")
    public ResponseResult getOneNews(@PathVariable("id") Integer id) {
        //调用service
        return wmNewsService.getOneNews(id);
    }

    /**
     * 人工审核自媒体文章失败
     *
     * @param dto
     * @return
     */
    @PostMapping("/auth_fail")
    public ResponseResult authNewsFail(@RequestBody NewsAuthDto dto) {
        log.info("人工审核文章失败,入参:{}", dto);
        //调用sercice
        return wmNewsService.authNewsFail(dto);
    }
    /**
     * 人工审核自媒体文章通过
     * 文章审核通过后,通过feign远程调用app端文章微服务进行文章保存
     * @param dto
     * @return
     */
    @PostMapping("/auth_pass")
    public ResponseResult authNewsPass(@RequestBody NewsAuthDto dto) {
        log.info("人工审核文章通过,入参:{}", dto);
        //调用sercice
        return wmNewsService.authNewsPass(dto);
    }

}
